import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// start
import other from './modules/other.js'
import {
	create,
	info,
	update,
	del
} from "@/common/js/api/index.js"
// end
import Http from '@/common/js/api/request.js'
import Util from '@/common/js/utils/util.js'
import Config from '@/common/js/config/index.js'
const store = new Vuex.Store({
	state: {
		/**
		 * start: 优化全局参数，新增参数位置
		 * */
		themeStyle: '',
		Development: 0,
		code: '',
		token: '',
		app_id: '',
		role_info: {
			//1用户 2掌柜 3店主 4商家
			role: 1,
			uid: 0,
			site_id: 0,
			code: '',
			//是否绑定wx_openid  0否  1是
			wx_openid_is_exits: ''
		}
	},
	mutations: {
		/**
		 * start: 储存全局状态
		 * */
		setData(state, params) {
			state = Object.assign(state, params);
		},
		setThemeStyle(state, ThemeStyle) {
			state.themeStyle = ThemeStyle
		},
		logout(state) {
			try {
				uni.clearStorageSync();
			} catch (e) {
				//TODO handle the exception
			}
		},
		login(state, data) {
			if (data.token) {
				state.token = data.token;
				uni.setStorageSync('token', data.token)
				uni.setStorage({
					key: 'token',
					data: data.token,
					success: (data) => {
						console.log("保存token成功")
						//Util.redirectTo('/pages/member/index/index');
					}
				});
			}
			if (data.app_id) {
				state.app_id = data.app_id;
				uni.setStorageSync('app_id', data.app_id)
			}

			if (data.role_info) {
				state.role_info = data.role_info;
			}

		}
		
	},
	actions: {
		/**
		 * start: 优化全局函数，新增函数位置
		 * */
		async info({
			state,
			commit
		}) {
			info().then(res => {
				
			});
		}
	},
	modules: {
		other
	}
})
export default store
